<!DOCTYPE html>
<html lang="en">
<head>
    <title>修改密码</title>
    <div th:include="base-libs-easyui :: base-libs-easyui" />
    <script th:src="'/quickJs/scripts/common/md5.js'"></script>
    <style>
        body{
            background-color: #FFF;
        }
    </style>
    <script type="text/javascript">
        $(function() {
            initView();
        });

        function initView()
        {
            $("#oldPwd").focus();
            $("#formUpdatePwd").attr("action", "/plat/savePwd");
            $("body").find(".form-control").each(function(){
                $(this).QuickField("addNotNullClass");
            });
            $("button").on("click", btnClickHandler);
        }

        /**按钮点击回调*/
        function btnClickHandler(){
            var action = $(this).attr("action");
            if("savePwd" == action){
                savePwdBtnHandler();
            }
        }

        /**保存密码*/
        function savePwdBtnHandler(){
            if($(".form-control").QuickValidate()){
                savePwd();
            }
        }
        function savePwd(){
            var hexOldPwd = hex_md5($("#oldPwd").val());
            var hexNewPwd = hex_md5($("#newPwd").val());
            $.QuickRemote.AjaxFiledFormSubmit("formUpdatePwd", savePwdHandler, {hexOldPwd: hexOldPwd, hexNewPwd: hexNewPwd});
        }
        function savePwdHandler(result){
            var state = result["state"];
            if(state)
            {
                $.QuickAlert.alertNormal("修改密码成功，请重新登录", {callback: function(){
                    parent.layer.closeAll();
                    parent.location = "/plat/ignore/login.html";
                }});
            }
            else
            {
                var info = result["info"];
                $.QuickAlert.alertFail({content: info["faultInfo"]});
            }
        }

        /**验证两次输入的密码是否相同*/
        function validateConfirmPwd(){
            var newPwd = $("#newPwd").val();
            var confirmPwd = $("#confirmPwd").val();
            if(newPwd != confirmPwd){
                return "两次输入的密码不同，请重新输入";
            }
        }
    </script>
</head>
<body>
<form id="formUpdatePwd">
    <table class="form-table">
        <tr>
            <td class="td-text">
                <label>原始密码</label>
            </td>
            <td class="td-content">
                <input id="oldPwd" class="form-control" type="password"
                       quick-config="label:'原始密码', validateProxy:'notNull', length: '64'">
            </td>
        </tr>
        <tr>
            <td class="td-text">
                <label>新密码</label>
            </td>
            <td class="td-content">
                <input id="newPwd" class="form-control" name="newPwd" type="password"
                       quick-config="label:'新密码', validateProxy:'notNull', length: '64'">
            </td>
        </tr>
        <tr>
            <td class="td-text">
                <label>确认密码</label>
            </td>
            <td class="td-content">
                <input id="confirmPwd" class="form-control" name="confirmPwd" type="password"
                       quick-config="label:'确认密码', validateProxy:'notNull validateConfirmPwd', length: '64'">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button action="savePwd" type="button" style="float: right; margin-right: 20px;">保存密码</button>
            </td>
        </tr>
    </table>
</form>
</body>
</html>